package com.lzw.okgoutils.http.struct;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class StringObjectMap extends HashMap<String, Object> {
    private List<String> mKeyList = null;
    private List<Object> mValueList = null;

    public List<String> getKeyList(){
        if (isEmpty()) {
            return null;
        }
        if (mKeyList == null) {
            mKeyList = new ArrayList<String>();
        }
        for (Entry<String, Object> entry : this.entrySet()) {
             mKeyList.add(entry.getKey());
        }
        return mKeyList;
    }

    public List<Object> getValueList(){
        if (isEmpty()) {
            return null;
        }
        if (mValueList == null) {
            mValueList = new ArrayList<Object>();
        }
        for (Entry<String, Object> entry : this.entrySet()) {
            mValueList.add(entry.getValue());
        }
        return mValueList;
    }

    @Override
    public String toString() {
        if (isEmpty()) {
            return "[]";
        }
        StringBuilder sb = new StringBuilder();
        for (Entry<String, Object> entry : this.entrySet()) {
            sb.append("[")
              .append(entry.getKey())
              .append("=")
              .append(entry.getValue().toString())
              .append("]")
              .append(",");
        }
        String res = sb.toString();
        return res.substring(0, res.length()-1);
    }
}